<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/5/15 0015
 * Time: 11:02
 */

namespace App\Socket\Packets;


use App\Socket\Models\Protocol;

class DispatchPacket
{
    /**
     * 分发数据包
     * @param Protocol $protocol
     * @param int $fd
     * @return null|Protocol
     */
    public static function handle(Protocol $protocol,int $fd)
    {
        $code = $protocol->getCode();
        $result = null;
        switch ($code)
        {
            //心跳包
            case Protocol::CODE_HEARTBEAT:
                $result = HeartBeatPacket::instance()->handle($protocol->getData());
                break;
            //登录
            case Protocol::CODE_LOGIN:
                $result = UserPacket::instance()->login($protocol->getData(),$fd);
                break;
            //登出
            case Protocol::CODE_LOGOUT:
                UserPacket::instance()->logout($protocol->getData(),$fd);
                break;
        }
        return $result;
    }
}